<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

    <title>图片管理工具</title>

    <jsp:include page="/common/header.jsp" />

    <link rel="stylesheet" href="<%=request.getContextPath()%>/image/image.css" />

  </head>
  <body>

    <jsp:include page="/common/top.jsp?navType=li-img-pz" />

    <div class="container">
      <div class="row">
        <div class="col-md-6 container-fluid">

          <c:forEach items="${repositoryList }" var="repo">

            <div class="panel panel-success">
              <div class="panel-heading">
                ${repo.path}

                <c:if test="${repo.path != defaultDir }">
                  <input type="button" class="btn btn-xs btn-danger" method="102" repositoryPath="${repo.path }" value="删除" />
                  <input type="button" class="btn btn-xs btn-danger" method="103" repositoryPath="${repo.path }" value="切换" />
                  <input type="button" class="btn btn-xs btn-danger" method="104" repositoryPath="${repo.path }" value="重新生成缩略图" />
                </c:if>


              </div>
              <div class="panel-body">

              </div>
            </div>
          </c:forEach>

        </div>




        <div class="col-md-6 container-fluid">

          <div id="result" class="alert alert-success" role="alert">
            错误信息：无
          </div>
          <div class="input-group">
            <input id="repositoryPathInput" type="text" class="form-control" aria-describedby="basic-addon" value="${pdfFolder }" placeholder="资料库地址" />
            <span class="input-group-btn"> <input class="btn btn-default btn-warning" type="button" method="101" value="添加新资料库" /> </span>
          </div>

          <h1></h1>


        </div>
      </div>
    </div>

  </body>
</html>

<script type="text/javascript">
	//普通请求
	function normalRequest(method, folderPath) {
		var url = "<c:url value='imageConfig' />";
		$("body").mLoading("show");
		$.ajax({
			type : "POST",
			url : url,
			data : "method=" + method + "&imageFoldePath=" + folderPath,
			success : function(msg) {
				window.location.href = window.location.href;
			},
			error : function() {
				showResult("出错啦！", false);
				$("body").mLoading("hide");
			}
		});
	}

	//切换资料库
	$("input[method='103']").click(function() {
		var repositoryPath = $(this).attr("repositoryPath");
		var method = $(this).attr("method");
		normalRequest(method, repositoryPath);
	});

	//删除资料库
	$("input[method='102']").click(function() {
		var repositoryPath = $(this).attr("repositoryPath");
		var method = $(this).attr("method");
		normalRequest(method, repositoryPath);
	});

	//生成缩略图
	$("input[method='104']").click(function() {
		var repositoryPath = $(this).attr("repositoryPath");
		var method = $(this).attr("method");
		normalRequest(method, repositoryPath);
	});

	//添加资料库
	$("input[method='101']").click(function() {
		var repositoryPath = $("#repositoryPathInput").val();
		normalRequest(101, repositoryPath);
	});

	function reloadFolder() {
		window.location.href = window.location.href;
	}
	function showResult(msg, isSuccess) {
		if (isSuccess) {
			$("#result").addClass("alert-success");
		} else {
			$("#result").addClass("alert-danger");
		}

		$("#result").html(msg);
		$("#result").show();
	}

	var url = "<c:url value='imageConfig' />";
</script>